﻿using EasySchedule.DataModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasySchedule.ViewModels
{
    public class ParticipantViewModel : ViewModelBase
    {
        private DataModel.ParticipantType participant;
        private string name;
        private string phoneNumber;
        private bool[] preferences;
        private Uri smallUri;
        private string emailAddress;
        private System.Collections.ObjectModel.ObservableCollection<DateTime> observableCollection;

        public ParticipantViewModel(ParticipantType participant)
        {            
            this.participant = participant;
            Name = this.participant.name;
            PhoneNumber = this.participant.participantPhoneNumber;
            EmailAddress = this.participant.participantEmailAddress;
            if (this.participant.avatarSmallUri != null && this.participant.avatarSmallUri.Value != null) 
                SmallUri = new Uri(this.participant.avatarSmallUri.Value);
            Preferences = ConvertToBoolArray(this.participant.preferences);
              
        }

        private bool[] ConvertToBoolArray(string[] pref)
        {
            bool[] boolArray = new bool[pref.Count()];
            for (int i = 0; i < pref.Count(); i++)
            {
                boolArray[i] = pref[i] == "1" ? true : false;
            }
            return boolArray;
        }

        public string Name
        {
            get { return name; }
            set { SetProperty(ref name, value); }
        }

        public string PhoneNumber 
        {
            get { return this.phoneNumber; }
            set { SetProperty(ref this.phoneNumber, value);} 
        }

        public string EmailAddress 
        {
            get { return this.emailAddress; }
            set { SetProperty(ref this.emailAddress, value); } 
        }

        public Uri SmallUri 
        {
            get { return this.smallUri; }
            set { SetProperty(ref this.smallUri, value); } 
        }

        public bool[] Preferences 
        {
            get { return this.preferences; }
            set { SetProperty(ref this.preferences, value); } 
        }
    }
}
